#include "lastStoneWeight.h"
int lastStoneWeight(std::vector<int> &stones) {
    std::priority_queue<int> pq;
    for (auto e:stones)
        pq.emplace(e);
    while (pq.size() >= 2) {
        int max_value = pq.top();
        pq.pop();
        int second_value = pq.top();
        pq.pop();
        if (max_value > second_value)
            pq.push(max_value - second_value);

    }
    return pq.size()==1?pq.top():0;
}
